package com.qifenqian.turbot.net

import com.qifenqian.turbot.config.Constant.SP_ACCOUNT
import com.qifenqian.turbot.config.Constant.SP_KEY_RESTAURANT_ID
import com.qifenqian.turbot.config.Constant.SP_KEY_USER_CODE
import com.qifenqian.turbot.module.entity.request.*
import com.qifenqian.turbot.module.entity.response.*
import com.qifenqian.turbot.module.entity.response.dish.CategoryEntity
import com.qifenqian.turbot.module.entity.response.dish.DishEntity
import com.qifenqian.turbot.module.entity.response.marketing.*
import com.qifenqian.turbot.module.entity.response.restaurant.*
import com.qifenqian.turbot.module.entity.response.statistic.SoldDishEntity
import com.qifenqian.turbot.module.entity.response.statistic.StatisticsEntity
import com.qifenqian.turbot.util.SpUtils
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * @author H
 * @createDate 2018/12/29 17:32
 * @description
 * @see [NetClient]
 * @since
 */
class TurbotClient {

    //-------------------------------登录注册模块---------------------------
    fun checkVersion(): Observable<BaseEntity<VersionEntity>> {
        val map: Map<String, Any> = mutableMapOf(
                "platform" to 1)
        return RetrofitFactory.getRetrofitService(TurbotService.SettingService::class.java)
                .checkVersion(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun giveFeedback(content: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "restaurantId" to SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT),
                "feeBackContent" to content)
        return RetrofitFactory.getRetrofitService(TurbotService.SettingService::class.java)
                .giveFeedback(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun sendSmsCode(type: Int, phone: String = "0"): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "type" to type,
                "phone" to phone)
        return RetrofitFactory.getRetrofitService(TurbotService.LoginEtcService::class.java)
                .sendSmsCode(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun login(userCode: String, password: String, loginType: Int, smsCode: String): Observable<BaseEntity<LoginEntity>> {
        val map: Map<String, Any> = mutableMapOf(
                "userCode" to userCode,
                "password" to password,
                "loginType" to loginType,
                "smsCode" to smsCode)
        return RetrofitFactory.getRetrofitService(TurbotService.LoginEtcService::class.java)
                .login(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun resetPassword(userCode: String, password: String, smsCode: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "userCode" to userCode,
                "password" to password,
                "smsCode" to smsCode)
        return RetrofitFactory.getRetrofitService(TurbotService.LoginEtcService::class.java)
                .resetPassword(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun logout(userCode: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "userCode" to userCode)
        return RetrofitFactory.getRetrofitService(TurbotService.LoginEtcService::class.java)
                .logout(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun register(userCode: String, smsCode: String, password: String): Observable<BaseEntity<LoginEntity>> {
        val map: Map<String, Any> = mutableMapOf(
                "userCode" to userCode,
                "smsCode" to smsCode,
                "password" to password)
        return RetrofitFactory.getRetrofitService(TurbotService.LoginEtcService::class.java)
                .register(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun qualityCertificationFirst(userCode: String, frontPhotoOfIdCard: String, backPhotoOfIdCard: String, bankNo: String, bankName: String, phone: String, smsCode: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "userCode" to userCode,
                "frontPhotoOfIdCard" to frontPhotoOfIdCard,
                "backPhotoOfIdCard" to backPhotoOfIdCard,
                "bankNo" to bankNo,
                "bankName" to bankName,
                "phone" to phone,
                "smsCode" to smsCode)
        return RetrofitFactory.getRetrofitService(TurbotService.LoginEtcService::class.java)
                .qualityCertificationFirst(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun qualityCertificationSecond(userCode: String, businessLicense: String, storePhotos: MutableList<String>, cateringServiceLicense: String): Observable<BaseEntity<Nothing>> {
        // TODO: 2018/12/29 17:15 上传数组? ----->
        val map: Map<String, Any> = mutableMapOf(
                "userCode" to userCode,
                "businessLicense" to businessLicense,
                "storePhotos" to storePhotos,   //
                "cateringServiceLicense" to cateringServiceLicense)
        return RetrofitFactory.getRetrofitService(TurbotService.LoginEtcService::class.java)
                .qualityCertificationSecond(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun modifyPhone(oldPhone: String, password: String, newPhone: String, smsCode: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "oldPhone" to oldPhone,
                "password" to password,
                "newPhone" to newPhone,
                "smsCode" to smsCode)
        return RetrofitFactory.getRetrofitService(TurbotService.LoginEtcService::class.java)
                .modifyPhone(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun modifyPassword(oldPassword: String, newPassword: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "oldPassword" to oldPassword,
                "newPassword" to newPassword)
        return RetrofitFactory.getRetrofitService(TurbotService.LoginEtcService::class.java)
                .modifyPassword(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    //-----------------------------餐厅信息模块-------------------
    fun getRestaurantInfo(): Observable<BaseEntity<RestaurantEntity>> {
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .getRestaurantInfo(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun editShortName(shortName: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "id" to SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT),
                "shortName" to shortName)
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .editShortName(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun getPhotoList(): Observable<BaseEntity<List<RestaurantPhotoEntity>>> {
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .getPhotoList(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

//    fun savePhotoList(ids: MutableList<Int>, restaurantPhotoPaths: MutableList<String>): Observable<BaseEntity<Nothing>> {
//        // TODO: 2019/1/2 9:33 上传数组的方法 ----->
//        //-------方法一-------
//        val jsonRoot = JSONObject()
//        var jsonData: JSONObject? = null
//        for (i in 0 until ids.size) {
//            jsonData = JSONObject()
//            jsonData.put("id", ids[i])
//            jsonData.put("restaurantPhotoPath", restaurantPhotoPaths[i])
//            jsonData.put("restaurantId", SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
//        }
//        jsonRoot.put("photoList", jsonData)
//        val photoList: MutableList<PhotoRequest.Photo> = mutableListOf()
//        for (i in 0 until ids.size) {
//            val photo = PhotoRequest.Photo(ids[i], SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT), restaurantPhotoPaths[i])
//            photoList.add(photo)
//            PhotoRequest(photoList)
//        }
//        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
//                .savePhotoList(body = RetrofitFactory.getRequestBody(jsonRoot))     //方法一
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//    }

    fun savePhotoList(request: PhotoRequest): Observable<BaseEntity<Nothing>> {
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .savePhotoList(body = RetrofitFactory.getRequestBody(request))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun getCuisineList(): Observable<BaseEntity<List<CuisineEntity>>> {
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .getCuisineList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun chooseCuisine(cuisine: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "id" to SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT),
                "cuisine" to cuisine)
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .chooseCuisine(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun setAvailableChooseSeat(onlineReservation: Int): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "id" to SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT),
                "onlineReservation" to onlineReservation)
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .setAvailableChooseSeat(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun changeRestaurantPhone(restaurantPhone: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "id" to SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT),
                "restaurantPhone" to restaurantPhone)
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .changeRestaurantPhone(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun changeBusinessTime(openTime: String, closeTime: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "id" to SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT),
                "openTime" to openTime,
                "closeTime" to closeTime)
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .changeBusinessTime(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun changeAddress(province: String, city: String, area: String, address: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "id" to SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT),
                "province" to province,
                "city" to city,
                "area" to area,
                "address" to address)
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .changeAddress(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun changePersonConsume(consumePerPerson: Int): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "id" to SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT),
                "consumePerPerson" to consumePerPerson)
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .changePersonConsume(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun getRestaurantIntroduction(): Observable<BaseEntity<RestaurantEntity>> {
        val map: Map<String, Any> = mutableMapOf("restaurantId" to SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .getRestaurantIntroduction(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun changeRestaurantIntroduction(introduction: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "id" to SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT),
                "introduction" to introduction)
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .changeRestaurantIntroduction(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    //----------------------------服务模块------------------------
    fun getServiceList(): Observable<BaseEntity<List<RestaurantServiceEntity>>> {
//        val map: Map<String, Any> = mutableMapOf("test" to test)
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .getServiceList(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun addService(serviceName: String): Observable<BaseEntity<RestaurantServiceEntity>> {
        val map: Map<String, Any> = mutableMapOf(
                "restaurantId" to SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT),
                "serviceName" to serviceName)
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .addService(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())

    }

    fun deleteService(serviceId: Int): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf("id" to serviceId)
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .deleteService(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    /**
     * TODO: 2018/12/26 9:42 修改传递的参数 ----->
     */
    fun chooseService(request: ServiceRequest): Observable<BaseEntity<RestaurantServiceEntity>> {
        // TODO: 2018/12/29 17:21
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .chooseService(body = RetrofitFactory.getRequestBody(request))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    //-----------------------------餐桌模块------------------------
    fun getTableInfo(): Observable<BaseEntity<RestaurantTableEntity>> {
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .getTableInfo(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun deleteTableInfo(id: Int): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "id" to id)
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .deleteTableInfo(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun saveTableInfo(saveTableRequest: RestaurantTableEntity): Observable<BaseEntity<Nothing>> {
        return RetrofitFactory.getRetrofitService(TurbotService.RestaurantService::class.java)
                .saveTableInfo(body = RetrofitFactory.getRequestBody(saveTableRequest))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    //-----------------------------职员模块------------------------
    fun getStaffList(): Observable<BaseEntity<List<StaffEntity>>> {
        return RetrofitFactory.getRetrofitService(TurbotService.StaffService::class.java)
                .getStaffList(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun addStaff(userName: String, userCode: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "restaurantId" to SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT),
                "userName" to userName,
                "userCode" to userCode)
        return RetrofitFactory.getRetrofitService(TurbotService.StaffService::class.java)
                .addStaff(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())

    }

    fun editStaff(staffId: Int, staffName: String, staffPhone: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "id" to staffId,
                "userName" to staffName,
                "userCode" to staffPhone)
        return RetrofitFactory.getRetrofitService(TurbotService.StaffService::class.java)
                .editStaff(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun deleteStaff(staffId: Int): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf("id" to staffId)
        return RetrofitFactory.getRetrofitService(TurbotService.StaffService::class.java)
                .deleteStaff(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    //-----------------------------用户评论模块------------------------
    fun getCommentList(page: Int): Observable<BaseEntity<List<CommentEntity>>> {
        return RetrofitFactory.getRetrofitService(TurbotService.CommentService::class.java)
                .getCommentList(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT), pageSize = 10, pageNo = page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun reply(commentId: Int, replyContent: String, replyUserCode: String): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "commentId" to commentId,
                "replyContent" to replyContent,
                "replyUserCode" to replyUserCode)
        return RetrofitFactory.getRetrofitService(TurbotService.CommentService::class.java)
                .reply(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    //-----------------------------菜品模块------------------------
    fun getCategoryList(): Observable<BaseEntity<List<CategoryEntity>>> {
        return RetrofitFactory.getRetrofitService(TurbotService.DishService::class.java)
                .getCategoryList(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))

    }

    fun getAllDishList(): Observable<BaseEntity<List<DishEntity>>> {
        return RetrofitFactory.getRetrofitService(TurbotService.DishService::class.java)
                .getAllDishList(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
    }

    fun addCategory(dishTypeName: String): Observable<BaseEntity<CategoryEntity>> {
        val map: Map<String, Any> = mutableMapOf(
                "restaurantId" to SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT),
                "dishTypeName" to dishTypeName)
        return RetrofitFactory.getRetrofitService(TurbotService.DishService::class.java)
                .addCategory(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun addDish(request: DishAddEditRequest): Observable<BaseEntity<DishEntity>> {
        return RetrofitFactory.getRetrofitService(TurbotService.DishService::class.java)
                .addDish(body = RetrofitFactory.getRequestBody(request))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun editDish(request: DishAddEditRequest): Observable<BaseEntity<Nothing>> {
        return RetrofitFactory.getRetrofitService(TurbotService.DishService::class.java)
                .editDish(body = RetrofitFactory.getRequestBody(request))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun deleteDish(dishId: Int): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "id" to dishId)
        return RetrofitFactory.getRetrofitService(TurbotService.DishService::class.java)
                .deleteDish(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun editCategory(dishTypeName: String, dishTypeId: Int): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf(
                "id" to dishTypeId,
                "dishTypeName" to dishTypeName)
        return RetrofitFactory.getRetrofitService(TurbotService.DishService::class.java)
                .editCategory(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun deleteCategory(dishTypeId: Int): Observable<BaseEntity<Nothing>> {
        val map: Map<String, Any> = mutableMapOf("id" to dishTypeId)
        return RetrofitFactory.getRetrofitService(TurbotService.DishService::class.java)
                .deleteCategory(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun saveCategory(request: CategoryRequest): Observable<BaseEntity<Nothing>> {
        return RetrofitFactory.getRetrofitService(TurbotService.DishService::class.java)
                .saveCategory(body = RetrofitFactory.getRequestBody(request))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    //----------------------------首页统计数据模块------------------------
    fun getBusinessStatistics(date: String, type: Int): Observable<BaseEntity<StatisticsEntity>> {
        val map: Map<String, Any> = mutableMapOf(
                "userCode" to SpUtils.getInstance().getString(SP_KEY_USER_CODE, SP_ACCOUNT),
                "type" to type,
                "date" to date)
        return RetrofitFactory.getRetrofitService(TurbotService.StatisticsService::class.java)
                .getBusinessStatistics(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun getDishStatistics(date: String, type: Int): Observable<BaseEntity<List<SoldDishEntity>>> {
        val map: Map<String, Any> = mutableMapOf(
                "userCode" to SpUtils.getInstance().getString(SP_KEY_USER_CODE, SP_ACCOUNT),
                "type" to type,
                "date" to date)
        return RetrofitFactory.getRetrofitService(TurbotService.StatisticsService::class.java)
                .getDishStatistics(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    //----------------------------上传文件--------------------------
    fun uploadFile(filePath: String): Observable<UploadEntity> {
        return RetrofitFactory.getUploadService()
                .uploadDishIcon(file = RetrofitFactory.getRequestBody(filePath))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    //----------------------------营销--特价菜--------------------------
    fun getMarketingPage(): Observable<BaseEntity<MarketingHomeEntity>> {
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .getMarketingPage(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun getSpecialDishes(): Observable<BaseEntity<List<SpecialDishEntity>>> {
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .getSpecialDishes(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun saveSpecialDishes(request: SpecialDishEntity): Observable<BaseEntity<Nothing>> {
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .saveSpecialDishes(body = RetrofitFactory.getRequestBody(request))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun deleteSpecialDish(id: Int): Observable<BaseEntity<Nothing>> {
        val map = mapOf("id" to id)
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .deleteSpecialDish(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    //----------------------------营销--单品折扣--------------------------
    fun getDiscountDishes(): Observable<BaseEntity<DiscountDishEntity>> {
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .getDiscountDishes(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    /**
     * 添加菜品折扣 在onResume的RxBus传递数据响应的时候调用(应该废弃)
     * @param discountDishInfoId 菜品折扣单id
     */
    fun addDiscountDish(discountDishInfoId: Int, dishId: Int, discount: Double): Observable<BaseEntity<Nothing>> {
        val map = mapOf(
                "discountDishInfoId" to discountDishInfoId,
                "dishId" to dishId,
                "discount" to discount)
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .addDiscountDish(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    /**
     * @param id 菜品折扣id
     */
    fun editDiscountDish(id: Int, dishId: Int, discount: Double): Observable<BaseEntity<Nothing>> {
        val map = mapOf(
                "id" to id,
                "dishId" to dishId,
                "discount" to discount)
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .addDiscountDish(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    /**
     * @param id 菜品折扣id
     */
    fun deleteDiscountDish(id: Int): Observable<BaseEntity<Nothing>> {
        val map = mapOf("id" to id)
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .deleteDiscountDish(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun saveDiscountInfo(request: DiscountDishRequest): Observable<BaseEntity<Nothing>> {
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .saveDiscountInfo(body = RetrofitFactory.getRequestBody(request))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    /**
     * @param id 菜品折扣单id
     */
    fun deleteDiscountInfo(id: Int): Observable<BaseEntity<Nothing>> {
        val map = mapOf("id" to id)
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .deleteDiscountInfo(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    //----------------------------营销--闲时折扣--------------------------
    fun getFreeTimeDiscount(): Observable<BaseEntity<FreeTimeDiscountDetailEntity>> {
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .getFreeTimeDiscount(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun deleteFreeTimeDiscount(id: Int): Observable<BaseEntity<Nothing>> {
        val map = mapOf("id" to id)
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .deleteFreeTimeDiscount(body = RetrofitFactory.getRequestBody(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun getFreeTimeDiscountDetail(): Observable<BaseEntity<FreeTimeDiscountDetailEntity>> {
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .getFreeTimeDiscountDetail(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun saveFreeTimeDiscountDetail(request: FreeTimeDiscountDetailEntity): Observable<BaseEntity<Nothing>> {
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .saveFreeTimeDiscountDetail(body = RetrofitFactory.getRequestBody(request))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    //----------------------------营销--分享优惠券--------------------------
    fun getShareDiscount(): Observable<BaseEntity<ShareDiscountEntity>> {
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .getShareDiscount(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun saveShareDiscount(request: ShareDiscountEntity): Observable<BaseEntity<Nothing>> {
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .saveShareDiscount(body = RetrofitFactory.getRequestBody(request))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    //----------------------------营销--满减--------------------------
    fun getFullReduction(): Observable<BaseEntity<FullReductionEntity>> {
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .getFullReduction(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun saveFullReduction(request: FullReductionEntity): Observable<BaseEntity<Nothing>> {
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .saveFullReduction(body = RetrofitFactory.getRequestBody(request))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    //----------------------------营销--提前买单--------------------------
    fun getEarlyPayDiscount(): Observable<BaseEntity<EarlyPayDiscountEntity>> {
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .getEarlyPayDiscount(restaurantId = SpUtils.getInstance().getInt(SP_KEY_RESTAURANT_ID, -1, SP_ACCOUNT))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }

    fun saveEarlyPayDiscount(request: EarlyPayDiscountEntity): Observable<BaseEntity<Nothing>> {
        return RetrofitFactory.getRetrofitService(TurbotService.MarketingService::class.java)
                .saveEarlyPayDiscount(body = RetrofitFactory.getRequestBody(request))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
    }
}